import Vue from "vue";
import Router from "vue-router";
import Home from "./views/Home.vue";

Vue.use(Router);

const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error=> error)
}

export default new Router({
  mode: "history",
  base: process.env.BASE_URL,
  routes: [
    {
      path: "/",
      name: "login",
      component: resolve => require(['@/views/login.vue'], resolve)
    },
    {
      path:'/forget',
      name:'forget',
      component:resolve => require(['@/views/forget.vue'],resolve)
    },
    {
      path:'/home',
      component:resolve => require(['@/views/Home.vue'],resolve),
      meta:{title:'后台模板'},
      children:[
        {
          path:'index',
          component:resolve => require(['@/views/home/index.vue'],resolve),
          meta:{
            title:'首页'
          }
        },
        {
          path:'examine',
          component:resolve=>require(['@/views/home/product.vue'],resolve),
          meta:{
            title:'商品审核'
          }
        },
        {
          path:'product',
          meta:{
            title:'商品管理'
          },
          component:resolve => require(['@/views/product.vue'],resolve),
          children:[

            {
              path:'details',
              component:resolve=>require(['@/views/home/details.vue'],resolve),
              meta:{
                title:'商品详情'
              }
            }
          ]
        }  
      ]
    },
    {
      path: "/about",
      name: "about",
      // route level code-splitting
      // this generates a separate chunk (about.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () =>
        import(/* webpackChunkName: "about" */ "./views/About.vue")
    }
  ]
});
